from appium.webdriver.common.appiumby import AppiumBy
from base.base_page import BasePage
from time import sleep
import allure

class LoginPage(BasePage):
    # 更新为您的APP实际元素
    #密码登录
    PASSWORD_LOGIN = (AppiumBy.XPATH, '//android.widget.TextView[@text="密码登录"]')
    #手机号输入框
    PHONE_INPUT = (
        AppiumBy.XPATH,
        '//android.widget.LinearLayout[@resource-id="com.oxbix.spanlogistics:id/phoneEdit"]/android.widget.EditText'
    )
    #密码输入框
    PASSWORD_INPUT = (
        AppiumBy.XPATH,
        '//android.widget.LinearLayout[@resource-id="com.oxbix.spanlogistics:id/psdEdit"]/android.widget.EditText'
    )
    #协议
    PROTOCOL = (AppiumBy.ID, 'com.oxbix.spanlogistics:id/check_box_login_protocol')
    #登录按钮
    LOGIN_BTN = (AppiumBy.ID, 'com.oxbix.spanlogistics:id/loginBtn')

    @allure.step(f"Login with phone and password")
    def login(self, phone: str, password: str):
        try:
            self.click(self.PASSWORD_LOGIN)
            # sleep(1)
            self.logger.info(f"登录页面输入账号密码: {[phone, password]}")
            self.send_keys(self.PHONE_INPUT, phone)
            self.send_keys(self.PASSWORD_INPUT, password)
            self.click(self.PROTOCOL)
            self.click(self.LOGIN_BTN)
            # sleep(2)
        except Exception as e:
            self.logger.error(e)





